package presentationTier.actions;

import businessTier.IMovieFacade;
import businessTier.MovieFacade;
import core.Medium;
import core.MovieException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import presentationTier.dialogs.ChangeMediumDialog;

/**
 *
 * @author vojta
 */
public class ChangeMediumChangeAction implements ActionListener{

    ChangeMediumDialog dialog;

    public ChangeMediumChangeAction(ChangeMediumDialog aThis) {
        dialog = aThis;
    }

    public void actionPerformed(ActionEvent e) {
        Medium medium = (Medium) dialog.jComboBox1.getSelectedItem();
        String name = medium.getMedium();

        String result = JOptionPane.showInputDialog("Change medium name to: ", name);
        //JOptionPane.showMessageDialog(dialog, result);
        if (!result.equalsIgnoreCase("")) {
            try {
                medium.setMedium(result);
                IMovieFacade mf = MovieFacade.getInstance();
                mf.changeMedium(medium);
                mf.close();

                dialog.readMedia();

            } catch (MovieException ex) {
                ex.printStackTrace();
            }


        }


    }

}
